<?php 
	$member = isset($data) ? $data['Member'] : array();
	
    // kontakti
    $contacts = !empty($data['MemberContact']) ? $data['MemberContact'] : array('');
    
    // horovi
    $choirs = !empty($data['MemberChoir']) ? $data['MemberChoir'] : array('');
    
	// funkcije
	$member_functions = array();
	if(!empty($data['MemberChoirFunction'])) {
		$member_functions = Set::extract('{n}.function_id', $data['MemberChoirFunction']);
	}
	
    // glasovi
	$member_voices = array();
	if(!empty($data['MemberVoice'])) {
		$member_voices = Set::extract('{n}.voice', $data['MemberVoice']);
	}
?>


<?= $this->Form->create('Member', array('action'=>'save')) ?>
	<?= $this->Form->hidden('created', array('value'=>isset($data['created']) ? $data['created'] : date('Y-m-d H:i:s'))) ?>
	<?= $this->Form->hidden('updated', array('value'=>date('Y-m-d H:i:s'))) ?>
	<?= $this->Form->hidden('updated_by', array('value'=>$this->Session->read("Auth.User.id"))) ?>
	<?= $this->App->input('id', 'hidden', @$member['id']) ?>
	
	<div class="left span50p">
		<?= $this->App->input('firstname', 'text', @$member['firstname']) ?>
		<?= $this->App->input('surname', 'text', @$member['surname']) ?>
		<?= $this->App->input('registration_date', 'date', empty($member['registration_date']) ? date("Y-m-d") : $member['registration_date']) ?>
		<?= $this->App->input('jmbg', 'text', @$member['jmbg']) ?>
		<?= $this->App->input('brlk', 'text', @$member['brlk']) ?>
		<?= $this->App->input('birthday', 'date', @$member['birthday']) ?>
		<?= $this->App->input('birth_place', 'text', @$member['birth_place']) ?>
		<?= $this->App->input('nationality', 'text', @$member['nationality']) ?>
		<?= $this->App->input('religion', 'text', @$member['religion']) ?>
		<?= $this->App->input('sex', 'radio', @$member['sex'], array('label' => 'sex', 'options' => array('male', 'female'))) ?>
		
	</div>
	<div class="left span50p">
		<?= $this->App->input('address', 'text', @$member['address']) ?>
		<?= $this->App->input('city', 'text', @$member['city']) ?>
		<?= $this->App->input('occupation', 'text', @$member['occupation']) ?>
		<?= $this->App->input('education', 'select', @$member['education'], array('options'=>$educations)) ?>
		<?= $this->App->input('passport_number', 'text', @$member['passport_number']) ?>
		<?= $this->App->input('passport_country', 'text', @$member['passport_country']) ?>
		<?= $this->App->input('category', 'select', @$member['category'], array('options' => $categories, 'empty'=>'')) ?>
		<?= $this->App->input('voice', 'select', @$member['voice'], array('options' => $voices, 'label'=>'voice', 'empty' => '')) ?>
		
		<?= $this->Form->label("_", strtotitle(__('choir')) . ":") ?>
		<div class="left" style="margin-left:10px">
			<?= $this->Form->checkbox('choir_sex_mixed', array('value' => 1, 'checked'=>(int)@$member['choir_sex_mixed']>0)) ?>
			<?= $this->Form->label('choir_sex_mixed', __('mixed') . " " . __('choir'), array('class'=>'inline auto')) ?>
			
			<br clear="all">
			<?= $this->Form->checkbox('choir_sex_male', array('value' => 1, 'checked'=>(int)@$member['choir_sex_male']>0)) ?>
			<?= $this->Form->label('choir_sex_male', __('male') . " " . __('choir'), array('class'=>'inline auto')) ?>
			
			<br clear="all">
			<?= $this->Form->checkbox('choir_sex_female', array('value' => 1, 'checked'=>(int)@$member['choir_sex_female']>0)) ?>
			<?= $this->Form->label('choir_sex_female', __('female') . " " . __('choir'), array('class'=>'inline auto')) ?>
		</div>
	</div>
	
	<br clear="all">
	
    <fieldset class="multi-inputs">
        <legend><?= strtotitle(__('contacts')) ?></legend>
        <? foreach($contacts as $contact): ?>
        <div class="left span50p multi-input">
            <?= $this->Form->select('MemberContact.contact_type.', $contact_types, array(
                'value' => @$contact['contact_type'],
                'empty' => false,
                'class' => 'span30p'
            )) ?>
            <?= $this->Form->text('MemberContact.contact_value.', array('value' => @$contact['contact_value'])) ?>
        </div>
        <? endforeach; ?>
    </fieldset>
	
	<fieldset class="checkbox-container">
		<legend><?= strtotitle(__('functions')) ?></legend>
		<? foreach($functions as $function_id=>$function): ?>
		<div class="left span30p">
			<?= $this->Form->checkbox("MemberChoirFunction..function_id", array('value' => $function_id, 'checked'=>in_array($function_id, $member_functions), 'id'=>'function_'.$function_id, 'hiddenField'=>false)) ?>
			<?= $this->Form->label("MemberChoirFunction.", __($function), array('for'=>'function_'.$function_id)) ?>
		</div>
		<? endforeach; ?>
	</fieldset>

	<fieldset class="multi-inputs">
		<legend><?= strtotitle(__('choirs')) ?></legend>
		<? foreach($choirs as $choir): ?>
        <div class="left multi-input">
        	<?= $this->Form->label('_', strtotitle(__('choir')) . ':') ?>
            <?= $this->Form->text('MemberChoir.choir.', array('value' => @$choir["choir"])) ?>
            <?= $this->Form->label('_', strtotitle(__('from')) . ':', array('class'=>'inline auto')) ?>
            <?= $this->Form->text('MemberChoir.date_from.', array('value' => @$choir["date_from"], 'class'=>'datepicker')) ?>
            <?= $this->Form->label('_', strtotitle(__('to')) . ':', array('class'=>'inline auto')) ?>
            <?= $this->Form->text('MemberChoir.date_to.', array('value' => @$choir["date_to"], 'class'=>'datepicker')) ?>
            <?= $this->Form->label('_', strtotitle(__('active'), true) . ':', array('class'=>'inline auto')) ?>
            <?= $this->Form->checkbox('MemberChoir.active.', array('value' => 1, 'checked'=>@$choir['active'], 'hiddenField'=>false)) ?>
        </div>
        <? endforeach; ?>
	</fieldset>
	
	<fieldset class="left span40p" style="margin-right:20px">
		<legend><?= strtotitle(__('father')) ?></legend>
		
		<?= $this->Form->hidden('MemberFather.type', array('value'=>'father')) ?>
		<?= $this->element('parent', array('data' => @$data['MemberFather'], 'name' => 'MemberFather')) ?>
		
	</fieldset>
	<fieldset class="left span40p">
		<legend><?= strtotitle(__('mother')) ?></legend>
		
		<?= $this->Form->hidden('MemberMother.type', array('value'=>'mother')) ?>
		<?= $this->element('parent', array('data' => @$data['MemberMother'], 'name' => 'MemberMother')) ?>
	</fieldset>
	<br clear="all">
<?= $this->Form->end(strtotitle(__('save'))) ?>
<br clear="all">
